package com.frost500.orderservice.service.impl;

import com.frost500.orderservice.client.IntegrationDemoClient;
import com.frost500.orderservice.service.OrderService;
import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *
 */
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private IntegrationDemoClient integrationDemoClient;

    @Override
    public void createUnlock(Long id) {
        try {
            integrationDemoClient.deductUnlock(id);
        } catch (FeignException e) {
            log.error("下单失败，原因:{}", e.contentUTF8());
            e.printStackTrace();
            throw new RuntimeException(e.contentUTF8());
        }
    }

    @Override
    public void createLocked(Long id) {
        try {
            integrationDemoClient.deductLocked(id);
        } catch (FeignException e) {
            log.error("下单失败，原因:{}", e.contentUTF8());
            e.printStackTrace();
            throw new RuntimeException(e.contentUTF8());
        }
    }

    @Override
    public void createDistributeLocked(Long id) {
        try {
            integrationDemoClient.deductDistributeLocked(id);
        } catch (FeignException e) {
            log.error("下单失败，原因:{}", e.contentUTF8());
            e.printStackTrace();
            throw new RuntimeException(e.contentUTF8());
        }
    }

    @Override
    public void insertStorage() {
        integrationDemoClient.insertStorage();
    }

    @Override
    public void insertStorageLocked() {
        integrationDemoClient.insertStorageLocked();
    }

    @Override
    public void insertStorageDistributeLocked() {
        integrationDemoClient.insertStorageDistributeLocked();
    }
}
